//
// Created by 吴喆 on 2020/3/3.
//

#include "Gui.h"

float Gui::currWidth = 0, Gui::currHeight = 0;
float Gui::lastWidth = 0, Gui::lastHeight = 0;

const char *glslVersion = "#version 330";
Gui *Gui::imGui = new Gui();/*NOLINT*/
std::vector<std::string> Gui::texts = std::vector<std::string>();



void Gui::render() {
    ImGuiWindowFlags window_flags = 0;
//    window_flags |= ImGuiWindowFlags_NoResize;
    ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
    ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);

    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();
    ImGui::Begin(u8"参数", nullptr, window_flags);
    ImGui::Text("当前帧数：%.1f", CTime::getInstance()->getFps());
    ImGui::Text("当前时间：%.1f", CTime::getInstance()->getTime());
    ImGui::Text("delta：%.2f", CTime::getInstance()->getDelta());

    ImGui::Text("npc pos：%.1f, %.1f", posX, posY);
    ImGui::Text("player pos：%.1f, %.1f", posX1, posY1);

    ImVec2 lastSize = ImGui::GetWindowSize();
    ImVec2 lastPos = ImGui::GetWindowPos();

    float wRatio = currWidth / Gui::lastWidth;
    float hRatio = currHeight / Gui::lastHeight;
    ImGui::SetWindowSize(ImVec2(lastSize.x * wRatio, lastSize.y * hRatio));
    ImGui::SetWindowPos(ImVec2(lastPos.x * wRatio, lastPos.y * hRatio));
    Gui::lastWidth = currWidth;
    Gui::lastHeight = currHeight;
    ImGui::End();

    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

}

void Gui::showPlayerPos(float x, float y) {
    posX = x;
    posY = y;
}
void Gui::showPlayerPos1(float x, float y) {
    posX1 = x;
    posY1 = y;
}
